home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / basic / _slist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  2.3 KB  |  130 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _slist.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #include <LEDA/impl/slist.h>
  16.  
  17. //------------------------------------------------------------------------------
  18. // Members of class SLIST
  19. //------------------------------------------------------------------------------
  20.  
  21. SLIST::SLIST()      
  22. { h=0; 
  23.   t=0;
  24.   count=0;
  25.   iterator=0; 
  26. }
  27.  
  28. SLIST::SLIST(GenPtr a) 
  29. { h=t=new slink(a,0);
  30.   count=1; 
  31.   iterator=0;  
  32. }
  33.  
  34.  
  35. SLIST::SLIST(const SLIST& x)
  36. { register slink* p;
  37.  
  38.   iterator=h=t=0; 
  39.   count = 0; 
  40.                               
  41.   for (p = x.h; p; p = p->succ) append(p->e); 
  42.  
  43.   if (!int_type())
  44.     for (p = h; p; p = p->succ) x.copy_el(p->e);
  45. }
  46.  
  47. GenPtr SLIST::pop()    
  48. { if (iterator!=0) error_handler(1,"pop: deletion while iterator is active");
  49.   GenPtr res;
  50.   if (h) 
  51.   { if (t==h) t = 0;
  52.     slink* x=h; 
  53.     res = x->e;
  54.     h=x->succ; 
  55.     delete x;
  56.     count--;
  57.    }
  58.   return res;
  59. }
  60.  
  61. /*
  62. void SLIST::del_succ(slink* p)    
  63. { slink* q = p->succ;
  64.   if (q) 
  65.   { if (t==q) t = p;
  66.     p->succ = q->succ; 
  67.     delete q;
  68.     count--;
  69.    }
  70. }
  71. */
  72.  
  73.  
  74. slink* SLIST::insert(GenPtr a, slink* p)   
  75. { if (iterator!=0) 
  76.          error_handler(2,"insert: insertion while iterator is active");
  77.   count++;
  78.   p->succ = new slink(a,p->succ); 
  79.   if (t==p) t = p->succ;
  80.   return h;
  81. }
  82.  
  83. void SLIST::conc(SLIST& l)
  84. { if (iterator!=0) error_handler(2,"conc: iterator is active");
  85.  if (count > 0) 
  86.    { t->succ = l.h;
  87.      if (l.count > 0) t = l.t; 
  88.     }
  89.  else 
  90.    { h = l.h; 
  91.      t = l.t; 
  92.     }
  93.  count = count+l.count;
  94.  l.h = l.t = 0;
  95.  l.count = 0;
  96. }
  97.  
  98.  
  99. slink* SLIST::cyclic_succ(slink* loc) const
  100. { if (loc==0) return 0;
  101.   return loc->succ? loc->succ : h;
  102.  }
  103.  
  104. SLIST& SLIST::operator=(const SLIST& x)
  105. { register slink* p;
  106.  
  107.   clear();
  108.  
  109.   for (p = x.h; p; p = p->succ) append(p->e); 
  110.  
  111.   if (!int_type())
  112.     for (p = h; p; p = p->succ) copy_el(p->e);
  113.  
  114.   return *this;
  115.  }
  116.  
  117. void SLIST::clear()
  118. { if (h==0) return;
  119.  
  120.   register slink* p;
  121.  
  122.   if(!int_type())
  123.     for(p = h; p; p = p->succ) clear_el(p->e);
  124.  
  125.   deallocate_list(h,t,sizeof(slink));
  126.   iterator=h=t=0;
  127.   count=0;
  128.  }
  129.